//
//  EPMHomeTableViewCell.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/27.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMHomeTableViewCell.h"

@interface EPMHomeTableViewCell()
@property (weak,nonatomic) EPMOriginalView* originalView;
@property (weak,nonatomic) EPMReetweView* reetView;
@property (weak,nonatomic) EPMBottomView* bottomView;
@property (strong,nonatomic) MASConstraint* bottomTopConstaint;
@end

@implementation EPMHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    EPMOriginalView* originalView = [[EPMOriginalView alloc]init];
    _originalView = originalView;
    [self.contentView addSubview:originalView];
    
    EPMReetweView* reetWeView = [EPMReetweView new];
    _reetView = reetWeView;
    [self.contentView addSubview:reetWeView];
    
    EPMBottomView* bottomView = [EPMBottomView new];
    _bottomView = bottomView;
    [self.contentView addSubview:bottomView];
    
    //约束
    [originalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.top.offset(5);
//        make.height.mas_equalTo(100);
    }];
    [reetWeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
        make.top.equalTo(originalView.mas_bottom).offset(ViewMargine);
//        make.height.mas_equalTo(50);
    }];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.offset(0);
      _bottomTopConstaint = make.top.equalTo(reetWeView.mas_bottom).offset(ViewMargine);
        make.height.mas_equalTo(35);
        make.bottom.offset(-ViewMargine);
        
    }];

}

- (void)setStatuesModel:(EPMStatuesViewModel *)statuesModel
{
    [_bottomTopConstaint deactivate];
    _statuesModel = statuesModel;
    self.originalView.statuesModel = statuesModel;
    if ( statuesModel.homeModel.retweeted_status == nil){
        self.reetView.hidden = YES;
        [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
         _bottomTopConstaint = make.top.equalTo(self.originalView.mas_bottom).offset(ViewMargine);
        }];
    }else{
        self.reetView.hidden = NO;
        self.reetView.statuesModel = statuesModel;
        [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            _bottomTopConstaint = make.top.equalTo(self.reetView.mas_bottom).offset(ViewMargine);
        }];
    }
    
}
@end
